package com.djinfo.work.controller;

import com.djinfo.work.common.bean.AjaxJson;
import com.djinfo.work.common.util.StringUtil;
import com.djinfo.work.entity.TbSysMenu;
import com.djinfo.work.entity.TbSysRoleMenu;
import com.djinfo.work.entity.TbSysRoles;
import com.djinfo.work.service.MenuService;
import com.djinfo.work.service.UserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ming 描述： 角色Controller
 */
@Controller
@RequestMapping("/role")
public class RoleController {
	private static final Log log = LogFactory.getLog(RoleController.class);
	/**
	 * 自动注入
	 */
	@Autowired
	private com.djinfo.work.service.RoleService RoleService;
	@Autowired
	private MenuService menuService;
	@Autowired
	private UserService userService;



	/**
	 * 角色信息主表实体类
	 */

	/**
	 * 角色列表
	 */
	@RequestMapping("/list.do")
	@ResponseBody
	public AjaxJson list(TbSysRoles tbSysRoles, Integer pagenum, Integer pagesize){
		AjaxJson ajaxJson =RoleService.list(tbSysRoles,pagenum,pagesize);
		return ajaxJson;

	}
	/**
	 * 某个用户的所有角色
	 */
	@RequestMapping("/userRoleList.do")
	@ResponseBody
	public AjaxJson oneUserRoleList(String uid){
		AjaxJson ajaxJson = RoleService.oneUserRoleList(uid);
		return ajaxJson;
	}
	/**
	 * 全部角色列表
	 */
	@RequestMapping("/allList.do")
	@ResponseBody
	public AjaxJson allList(){
		AjaxJson ajaxJson = RoleService.allList();
		return ajaxJson;
	}
	/**
	 * 角色编辑
	 */
	@RequestMapping("/edit.do")
	@ResponseBody
	public ModelAndView edit(TbSysRoles tbSysRoles){
		TbSysRoles tbSysRoles1 =RoleService.selectOne(tbSysRoles);
		return new ModelAndView("role/edit.html","tbSysRoles", tbSysRoles1);
	}
	/**
	 * 添加用户跳转
	 */
	@RequestMapping("/add.do")
	public ModelAndView add(){
		TbSysRoles tbSysRoles =new TbSysRoles();
		return new ModelAndView("role/edit.html","tbSysRoles", tbSysRoles);
	}
	/**
	 * 角色信息
	 */
	@RequestMapping("/info.do")
	@ResponseBody
	public AjaxJson info(TbSysRoles tbSysRoles){
		AjaxJson ajaxJson=RoleService.info(tbSysRoles);
		return ajaxJson;
	}

	/**
	 * 修改角色权限
	 */
	@RequestMapping("/saveOrUpdate.do")
	@ResponseBody
	public AjaxJson save(TbSysRoles tbSysRoles, String[] roles, HttpServletRequest request){
		AjaxJson ajaxJson = RoleService.save(tbSysRoles,roles,request);
		return ajaxJson;
	}

	/**
	 * 删除角色
	 */
	@RequestMapping("/delete.do")
	@ResponseBody
	public AjaxJson delete(String roleId){
		AjaxJson ajaxJson = RoleService.delete(roleId);
		return ajaxJson;
	}

}
